<!--
 * @Description:
 * @Author: zhangweigang
 * @Date: 2021-04-17 11:58:29
 * @LastEditTime: 2021-04-22 19:47:13
 * @LastEditors: zhangweigang
-->
<template>
  <div>
    <Header></Header>
    <curr-locat title="查看反馈"></curr-locat>
    <!-- 查看回复弹窗框 -->
    <div class="contain box">
      <a @click="returnInfo">返回</a>
      <div class="content-show" v-if="l > 0">
        <div v-for="(item, index) in replayList" :key="index">
          <div class="left">
            <h3 class="lb">{{ item.toUsername }}：</h3>
            <span>回复</span>
            <h3 class="lb">{{ item.username }}</h3>
            <p class="lb">#{{ item.replyDate }}</p>
          </div>
          <div class="right">
            <div class="info">{{ item.content }}</div>
            <div class="btn">
              <el-button class="btns" type="primary" size="mini" @click="replyInfoParams(item.commentId, item.id, item.toUserId, item.toUsername, item.userId, item.username)">回复</el-button>
            </div>
          </div>
          <!-- 第二层查看 -->
          <div class="secondInfo" v-for="(subItem, index) in item.nextNodes" :key="index">
            <div class="left">
              <h3 class="lb">{{ subItem.username }}</h3>
              <span>回复</span>
              <h3 class="lb">{{ subItem.toUsername }}</h3>
              <p class="lb">#{{ subItem.replyDate }}</p>
            </div>
            <div class="right">
              <div class="info">{{ subItem.content }}</div>
              <div class="btn">
                <el-button type="warning" size="mini" @click="replyInfoParams(subItem.commentId, subItem.id, subItem.toUserId, subItem.toUsername, subItem.userId, subItem.username)">回复</el-button>
              </div>
            </div>
            <!-- 第三层查看 -->
            <div class="secondInfo" v-for="(thirdInfo, index) in subItem.nextNodes" :key="index">
              <div class="left">
                <h3 class="lb">{{ thirdInfo.username }}</h3>
                <span>回复</span>
                <h3 class="lb">{{ thirdInfo.toUsername }}</h3>
                <p class="lb">#{{ thirdInfo.replyDate }}</p>
              </div>
              <div class="right">
                <div class="info">{{ thirdInfo.content }}</div>
                <!-- 最多是能回复两层 <div class="btn">
                  <el-button type="warning" size="mini" @click="replyInfoParams(thirdInfo.commentId, thirdInfo.id, thirdInfo.toUserId, thirdInfo.toUsername, thirdInfo.userId, thirdInfo.username)">回复</el-button>
                </div> -->
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="no-info" v-else>这条留言暂无回复！请等待...</div>
    </div>
    <!-- 回复消息弹出框 -->
    <el-dialog title="消息回复" :visible.sync="dialogReylayVisible">
      <el-form :model="replyForm" :rules="replyRules" ref="replyRef" class="demo-ruleForm">
        <el-form-item label="回复内容" prop="content">
          <el-input type="textarea" :rows="6" v-model="replyForm.content"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetReply">取 消</el-button>
        <el-button type="primary" @click="confirmInfo">确 定</el-button>
      </div>
    </el-dialog>
    <Footer></Footer>
  </div>
</template>

<script>
import { getSoleReplayInfo, getLeaveInfoData, replyLeaveInfo } from '../../network/product.js';
export default {
  data() {
    return {
      dialogReylayVisible: false,
      // 回复表单
      replyForm: {
        content: ''
      },
      replyRules: {
        content: [{ required: true, message: '回复内容不能为空！', trigger: 'blur' }]
      },
      currentUser: localStorage.getItem('username'),
      isShowFeed: false, // 是否显示回复留言信息
      replayList: [], // 回复的数据列表
      l: 0
    };
  },
  created() {
    // 查看留言内容
    this.leaveContent();
  },
  methods: {
    // 查看留言内容
    leaveContent() {
      let id = this.$route.params.id;
      // const loading = this.$loading({
      //   lock: true,
      //   text: 'Loading',
      //   spinner: 'el-icon-loading',
      //   background: 'rgba(0, 0, 0, 0.7)'
      // });
      getSoleReplayInfo(id).then((res) => {
        if (res.status === 200 && res.data.code === 0) {
          console.log(res.data.data);
          this.replayList = res.data.data;
          this.l = this.replayList.length;
          // const loading = this.$loading({
          //   lock: false,
          // });
        } else {
          this.$message({
            showClose: true,
            message: '未获取到留言，请联系管理员！',
            type: 'error',
            duration: 4000
          });
        }
      });
    },
    /**
     * 接收参数
     * @params commentId 内容ID
     * @params replayId 回复ID
     */
    replyInfoParams(commentId, replyId, toUserId, toUsername, userId, username) {
      this.dialogReylayVisible = true;
      this.replyForm = {
        commentId: commentId,
        replyId: replyId,
        toUserId: userId,
        toUsername: username,
        userId: toUserId,
        username: toUsername,
        delFlag: 1, // 未删除
        replyType: 2, // 给回复的回复
        sysRoleId: 0, // 必传参数，无需理会
        sysRoleName: '' // 必传参数，无需理会
      };
    },
    // 确定回复
    confirmInfo() {
      console.log(this.replyForm, '提交参数');
      this.$refs.replyRef.validate((valid) => {
        if (valid) {
          replyLeaveInfo(this.replyForm).then((res) => {
            if (res.data.code === 0 && res.status === 200) {
              this.dialogReylayVisible = false;
              this.$message({
                showClose: true,
                message: '恭喜您，回复成功！请等待...',
                type: 'success',
                duration: 4000
              });
            } else {
              this.$message({
                showClose: true,
                message: '回复失败，请联系管理员！',
                type: 'error',
                duration: 4000
              });
            }
          });
        } else {
          this.$message({
            showClose: true,
            message: '请先输入内容！',
            type: 'error',
            duration: 4000
          });
          return false;
        }
      });
    },
    // 返回
    returnInfo() {
      this.$router.back();
    },
    // 回复重置
    resetReply() {
      this.$refs.replyRef.resetFields();
      this.dialogReylayVisible = false;
    }
  }
};
</script>

<style lang="less" scoped>
.contain {
  position: relative;
}
.lb {
  display: inline-block;
}
.box {
  position: relative;
  a {
    position: absolute;
    right: 0%;
    top: -35px;
    color: red;
    font-size: 16px;
    cursor: pointer;
    &:hover {
      text-decoration: underline;
    }
  }
}
.content-show {
  position: relative;
  width: 100%;
}
.left {
  border-bottom: 1px solid #eee;
  margin: 5px 0;
  span {
    display: inline-block;
    font-size: 16px;
    padding: 0 5px;
  }
  p {
    font-size: 14px;
  }
}
.right {
  background-color: #9edff1;
  // padidng:
  .info {
    font-size: 16px;
    color: #333;
    padding: 10px 0 5px 35px;
  }
  .btn {
    text-align: right;
    border-top: 1px solid #eee;
    padding: 10px 0;
    .btns {
      margin-right: 10px;
    }
  }
}
.secondInfo {
  margin-left: 35px;
}
</style>
